//
//  WorkInfoViewController.m
//  51易借
//
//  Created by 张睿 on 2017/8/31.
//  Copyright © 2017年 张睿. All rights reserved.
//

#import "WorkInfoViewController.h"
#import "MemberInfoModel.h"
#import "MemberInfoTypePageModel.h"
@interface WorkInfoViewController ()<UITextFieldDelegate,STPickerAreaDelegate>
@property (strong, nonatomic) ZYKeyboardUtil *keyboardUtil;
@property (nonatomic,strong)MemberInfoTypePageModel * typePageModel;
@property (nonatomic, weak)UIView * topView;
@property (nonatomic, weak)UILabel * topLabel;
@property (nonatomic, weak)UIView * topInputView;
@property (nonatomic, strong)UILabel * workTypeLabel;
@property (nonatomic, strong)UIButton * workTypeButton;
@property (nonatomic, strong)UIImageView * workTypeImageView;
@property (nonatomic, strong)UIView * oneLineView;
@property (nonatomic,strong)UIImageView * cameraIcon;
@property (nonatomic, strong)UILabel * workNameLabel;
@property (nonatomic,strong)UITextField * workTypeField;
@property (nonatomic, strong)UITextField * workNameTextField;
@property (nonatomic, strong)UIView * twoLineView;
@property (nonatomic, strong)UILabel * workLocalLabel;
@property (nonatomic,strong)UITextField * workLocalField;
@property (nonatomic,strong)UITextField * workTimeTextField;
@property (nonatomic,strong)UITextField * getMoneyTextField;
@property (nonatomic, strong)UIButton * workLocalButton;
@property (nonatomic, strong)UIImageView * workLocalImageView;
@property (nonatomic, strong)UIView * threeLineView;
@property (nonatomic, strong)UITextField * workLocalTextField;
@property (nonatomic, strong)UIView * fourLineView;
@property (nonatomic, strong)UILabel * workTelLabel;
@property (nonatomic, strong)UITextField * workTelTextField;
@property (nonatomic, strong)UIView * fiveLineView;
@property (nonatomic, strong)UILabel * workImageLabel;
@property (nonatomic, weak)UILabel * explationLabel;
@property (nonatomic, weak)UIButton * cameraButton;
@property (nonatomic, strong)UIView * sixLineView;
@property (nonatomic, strong)UILabel * workTimeLabel;
@property (nonatomic, strong)UIButton * workTimeButton;
@property (nonatomic, strong)UIImageView * workTimeImageView;
@property (nonatomic, strong)UIView * sevenLineView;
@property (nonatomic, strong)UILabel * getMoneyTimeLabel;
@property (nonatomic, strong)UIButton * getMoneyTimeButton;
@property (nonatomic, strong)UIImageView * getMoneyTimeImageView;
@property (nonatomic, weak)UIButton * sureButton;
@property (nonatomic,strong)MemberInfoModel * pageModel;
@property (nonatomic,strong)ParaModel * para;

@end

@implementation WorkInfoViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = BACK_COLOR;
    [self getPageModel];
    [self setupNavBar];
    [self setupUI];
}


- (void)setupNavBar{
    
    self.title = @"工作信息";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"箭头"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToLastView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}


- (void)setupUI{
    
    UIView * topView = [UIView new];
    
    topView.backgroundColor = TOTAL_COLOR;
    
    self.topView = topView;
    
    [self.view addSubview:self.topView];
    
    
    UILabel * topLabel = [UILabel new];
    
    topLabel.textColor = ColorWithRGB(0x7f7f7f);
    topLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    topLabel.text = @"为保证借款申请顺利通过，请务必填写真实信息！";
    
    self.topLabel = topLabel;
    
    [self.view addSubview:self.topLabel];
    
    
    UIView * topInputView = [UIView new];
    
    topInputView.backgroundColor = [UIColor whiteColor];
    topInputView.layer.borderColor = [ColorWithRGB(0xe6e6e6) CGColor];
    topInputView.layer.borderWidth = 0.5 * SCREENH6;
    
    self.topInputView = topInputView;
    
    [self.view addSubview:self.topInputView];
    
    
    self.workTypeLabel = [self setupLabelWith:@"工作类型"];
    
    [self.topInputView addSubview:self.workTypeLabel];
    
    self.workTypeField = [self setupTextField:@"请选择"];
    
    [self.topInputView addSubview:self.workTypeField];
    
    
    
    self.workTypeButton = [self setupTitleButtonWith:@"请选择"];
    self.workTypeButton.tag = 0;
    [self.topInputView addSubview:self.workTypeButton];
    
    self.workTypeImageView = [self setupRightImage];
    
    [self.topInputView addSubview:self.workTypeImageView];
    
    self.oneLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.oneLineView];
    
    self.workNameLabel = [self setupLabelWith:@"单位名称"];
    
    [self.topInputView addSubview:self.workNameLabel];
    
    self.workNameTextField = [self setupTextField:@"请输入单位名称"];
    
    [self.topInputView addSubview:self.workNameTextField];
    
    self.twoLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.twoLineView];
    
    self.workLocalLabel = [self setupLabelWith:@"单位地址"];
    
    [self.topInputView addSubview:self.workLocalLabel];
    self.workLocalField = [self setupTextField:@"请选择单位地址"];
    
    [self.topInputView addSubview:self.workLocalField];

    self.workLocalButton = [self setupTitleButtonWith:@"请选择单位地址"];
    self.workLocalButton.tag = 1;

    [self.topInputView addSubview:self.workLocalButton];
    
    self.workLocalImageView = [self setupRightImage];
    
    [self.topInputView addSubview:self.workLocalImageView];
    
    self.threeLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.threeLineView];
    
    self.workLocalTextField = [self setupTextField:@"街道和门牌号"];
    
    [self.topInputView addSubview:self.workLocalTextField];
    
    self.fourLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.fourLineView];
    
    self.workTelLabel = [self setupLabelWith:@"单位电话"];
    
    [self.topInputView addSubview:self.workTelLabel];
    
    self.workTelTextField = [self setupTextField:@"请输入单位电话"];
    
    [self.topInputView addSubview:self.workTelTextField];
    
    self.fiveLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.fiveLineView];
    
    self.workImageLabel = [self setupLabelWith:@"工作证照"];
    
    [self.topInputView addSubview:self.workImageLabel];
    
    UILabel * explationLabel = [UILabel new];
    
    explationLabel.text = @"(选填，可提高通过率)";
    explationLabel.textColor = ColorWithRGB(0x7f7f7f);
    explationLabel.font = [UIFont systemFontOfSize:10 * SCREENH6];
    
    self.explationLabel = explationLabel;
    
    [self.topInputView addSubview:self.explationLabel];
    
    UIImageView * imageV = [UIImageView new];
    [imageV setContentMode:UIViewContentModeCenter];
    imageV.image =[UIImage imageNamed:@"相机"];
    self.cameraIcon = imageV;
    [self.topInputView addSubview:self.cameraIcon];

    UIButton * cameraButton = [UIButton new];
    
    [cameraButton addTarget:self action:@selector(didSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
    
    self.cameraButton = cameraButton;
    self.cameraButton.tag = 2;

    [self.topInputView addSubview:self.cameraButton];
    
    self.sixLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.sixLineView];
    
    self.workTimeLabel = [self setupLabelWith:@"工作时长"];
    
    [self.topInputView addSubview:self.workTimeLabel];
    self.workTimeTextField = [self setupTextField:@"请选择"];
    
    [self.topInputView addSubview:self.workTimeTextField];
    self.workTimeButton = [self setupTitleButtonWith:@"请选择"];
    self.workTimeButton.tag = 3;

    [self.topInputView addSubview:self.workTimeButton];
    
    self.workTimeImageView = [self setupRightImage];
    
    [self.topInputView addSubview:self.workTimeImageView];
    
    self.sevenLineView = [self setupLineView];
    
    [self.topInputView addSubview:self.sevenLineView];
    
    self.getMoneyTimeLabel = [self setupLabelWith:@"发薪日期"];
    
    [self.topInputView addSubview:self.getMoneyTimeLabel];
    self.getMoneyTextField = [self setupTextField:@"请选择"];
    
    [self.topInputView addSubview:self.getMoneyTextField];
    self.getMoneyTimeButton = [self setupTitleButtonWith:@"请选择"];
    self.getMoneyTimeButton.tag = 4;

    [self.topInputView addSubview:self.getMoneyTimeButton];
    
    self.getMoneyTimeImageView = [self setupRightImage];
    
    [self.topInputView addSubview:self.getMoneyTimeImageView];
    
    
    UIButton * sureButton = [UIButton new];
    //300 * 42
    [sureButton setTitle:@"保存" forState:UIControlStateNormal];
    [sureButton setBackgroundImage:[UIImage imageNamed:@"登录"] forState:UIControlStateNormal];
    [sureButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [sureButton addTarget:self action:@selector(didSaveButton) forControlEvents:UIControlEventTouchUpInside];
    sureButton.titleLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
    
    self.sureButton = sureButton;
    
    [self.view addSubview:self.sureButton];
    
    
    self.workNameTextField.delegate = self;
    self.workLocalTextField.delegate = self;
    self.workTelTextField.delegate = self;
    self.workTypeField.userInteractionEnabled = NO;
    self.workLocalField.userInteractionEnabled = NO;
    self.workTimeTextField.userInteractionEnabled = NO;
    self.getMoneyTextField.userInteractionEnabled = NO;

}


- (void)viewDidLayoutSubviews{
    
    [self.topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.leading.trailing.mas_equalTo(self.view);
        make.height.mas_equalTo(64);
    }];
    
    [self.topLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(13 * SCREENH6);
        make.top.mas_equalTo(self.topView.mas_bottom).offset(10 * SCREENH6);
    }];
    
    [self.topInputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(10 * SCREENH6);
        make.trailing.mas_equalTo(self.view).offset(-10 * SCREENH6);
        make.height.mas_equalTo(412 * SCREENH6);
        make.top.mas_equalTo(self.topLabel.mas_bottom).offset(7 * SCREENH6);
    }];
    
    [self.workTypeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topInputView).offset(20 * SCREENH6);
        make.leading.mas_equalTo(self.topInputView).offset(8 * SCREENH6);
    }];
    
    [self.workTypeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.topInputView).offset(-8 * SCREENH6);
        make.width.mas_equalTo(7.5 * SCREENH6);
        make.height.mas_equalTo(12.5 * SCREENH6);
        make.centerY.mas_equalTo(self.workTypeLabel);
    }];
    [self.workTypeField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workTypeLabel);
        make.trailing.mas_equalTo(self.workTypeImageView.mas_leading).offset(-10 * SCREENH6);
    }];

    [self.workTypeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workTypeLabel);
        make.trailing.mas_equalTo(self.workTypeImageView.mas_leading).offset(-10 * SCREENH6);
    }];
    
    [self.oneLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.topInputView).offset(2 * SCREENH6);
        make.trailing.mas_equalTo(self.topInputView).offset(-2 * SCREENH6);
        make.height.mas_equalTo(0.5 * SCREENH6);
        make.top.mas_equalTo(self.topInputView).offset(51 * SCREENH6);
    }];
    
    [self.workNameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workTypeLabel);
        make.top.mas_equalTo(self.oneLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.workNameTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.workTypeButton);
        make.centerY.mas_equalTo(self.workNameLabel);
        make.width.mas_equalTo(200 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.twoLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.oneLineView);
        make.top.mas_equalTo(self.oneLineView.mas_bottom).offset(51 * SCREENH6);
    }];
    
    [self.workLocalLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workNameLabel);
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(42 * SCREENH6);
    }];
    [self.workLocalField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.workTypeButton);
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    [self.workLocalButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.workTypeButton);
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.workLocalImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(self.workTypeImageView);
        make.centerY.mas_equalTo(self.workLocalButton).offset(-5 * SCREENH6);
    }];
    
    [self.threeLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.twoLineView.mas_bottom).offset(51 * SCREENH6);
        make.trailing.height.mas_equalTo(self.twoLineView);
        make.leading.mas_equalTo(self.topInputView).offset(87 * SCREENH6);
    }];
    
    [self.workLocalTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.height.width.mas_equalTo(self.workNameTextField);
        make.top.mas_equalTo(self.threeLineView.mas_bottom).offset(8 * SCREENH6);
    }];
    
    [self.fourLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.height.mas_equalTo(self.twoLineView);
        make.top.mas_equalTo(self.threeLineView.mas_bottom).offset(51 * SCREENH6);
    }];
    
    [self.workTelLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workLocalLabel);
        make.top.mas_equalTo(self.fourLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    
    [self.workTelTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.trailing.mas_equalTo(self.workLocalTextField);
        make.centerY.mas_equalTo(self.workTelLabel);
    }];
    
    [self.fiveLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.leading.trailing.mas_equalTo(self.fourLineView);
        make.top.mas_equalTo(self.fourLineView.mas_bottom).offset(51 * SCREENH6);
    }];
    
    [self.workImageLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.fiveLineView.mas_bottom).offset(20 * SCREENH6);
        make.leading.mas_equalTo(self.workTelLabel);
    }];
    
    [self.explationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workImageLabel);
        make.leading.mas_equalTo(self.workImageLabel.mas_trailing).offset(5 * SCREENH6);
    }];
    [self.cameraIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workImageLabel);
        make.trailing.mas_equalTo(self.workTelTextField);
        make.width.mas_equalTo(25 * SCREENH6);
        make.height.mas_equalTo(20 * SCREENH6);
    }];
    
    [self.cameraButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workImageLabel);
        make.trailing.mas_equalTo(self.workTelTextField).offset(10*SCREENH6);
        make.width.mas_equalTo(40 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];
    
    [self.sixLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.leading.trailing.mas_equalTo(self.fiveLineView);
        make.top.mas_equalTo(self.fiveLineView.mas_bottom).offset(51 * SCREENH6);
    }];
    
    [self.workTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workImageLabel);
        make.top.mas_equalTo(self.sixLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    [self.workTimeTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workTimeLabel);
        make.trailing.mas_equalTo(self.cameraIcon);
    }];
    [self.workTimeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.workTimeLabel);
        make.trailing.mas_equalTo(self.cameraIcon);
    }];
    
    [self.workTimeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.trailing.mas_equalTo(self.workLocalImageView);
        make.centerY.mas_equalTo(self.workTimeButton);
    }];
    
    [self.sevenLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.leading.trailing.mas_equalTo(self.sixLineView);
        make.top.mas_equalTo(self.sixLineView.mas_bottom).offset(51 * SCREENH6);
    }];
    
    [self.getMoneyTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.workTimeLabel);
        make.top.mas_equalTo(self.sevenLineView.mas_bottom).offset(20 * SCREENH6);
    }];
    [self.getMoneyTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.getMoneyTimeLabel);
        make.trailing.mas_equalTo(self.workTimeButton);
    }];
    [self.getMoneyTimeButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.getMoneyTimeLabel);
        make.trailing.mas_equalTo(self.workTimeButton);
    }];
    
    [self.getMoneyTimeImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.leading.trailing.mas_equalTo(self.workTimeImageView);
        make.centerY.mas_equalTo(self.getMoneyTimeButton);
    }];
    
    [self.sureButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view);
        make.top.mas_equalTo(self.topInputView.mas_bottom).offset(60 * SCREENH6);
        make.width.mas_equalTo(300 * SCREENH6);
        make.height.mas_equalTo(42 * SCREENH6);
    }];
}


- (void)didSelectedButton:(UIButton *)button{
    [self.view endEditing:YES];
    switch (button.tag) {
        case 0:
        {
            if(self.typePageModel)
            {
                [[WSZCustomPickView standViewWithDataArr:self.typePageModel.workTypeEnum Task:^(NSInteger index, id model) {
                    MemberInfoTypeModel * type = model;
                    self.para.workType = @(index);
                    self.workTypeField.text = type.name;
                }] show];
            }else
            {
                [self getTypeModel:^{
                    [[WSZCustomPickView standViewWithDataArr:self.typePageModel.workTypeEnum Task:^(NSInteger index, id model) {
                        MemberInfoTypeModel * type = model;
                        self.para.workType = @(index);
                        self.workTypeField.text = type.name;
                    }] show];
                }];
            }

        }
            break;
        case 1:
        {
            STPickerArea *pickerArea = [[STPickerArea alloc] init];
            pickerArea.delegate = self;
            pickerArea.contentMode = STPickerContentModeBottom;
            [pickerArea show];
        }
            break;
        case 2:
        {
            [BDImagePicker showImagePickerFromViewController:self allowsEditing:YES finishAction:^(UIImage *image) {
                if (image) {
 
                        [self upLoadImage:image complete:^(NSString *imageUrl) {
                            [button setImage:image forState:UIControlStateNormal];
                            self.para.workPhoto = imageUrl;
                        }];
                        
                   
                }
                
            }];
        }
            break;
        case 3:
        {
            if(self.typePageModel)
            {
                [[WSZCustomPickView standViewWithDataArr:self.typePageModel.addressSpanEnum Task:^(NSInteger index, id model) {
                    MemberInfoTypeModel * type = model;
                    self.para.workDuration = @(index);
                    self.workTimeTextField.text = type.name;
                }] show];
            }else
            {
                [self getTypeModel:^{
                    [[WSZCustomPickView standViewWithDataArr:self.typePageModel.addressSpanEnum Task:^(NSInteger index, id model) {
                        MemberInfoTypeModel * type = model;
                        self.para.workDuration = @(index);
                        self.workTimeTextField.text = type.name;
                    }] show];
                }];
            }

        }
            break;
        case 4:
        {
            
            NSMutableArray * arr = [NSMutableArray array];
            for(int i = 1; i <=31 ; i++)
            {
                [arr addObject:[NSString stringWithFormat:@"%d号",i]];
            }
            [[WSZCustomPickView standViewWithDataArr:arr Task:^(NSInteger index, id model) {
                self.para.workPayDate = @(index+1);
                self.getMoneyTextField.text = model;
            }] show];
        }
            break;
        default:
            break;
    }
    
    
}
- (void)pickerArea:(STPickerArea *)pickerArea province:(NSString *)province city:(NSString *)city area:(NSString *)area{
    NSString *text = [NSString stringWithFormat:@"%@ %@ %@", province, city, area];
    
    self.workLocalField.text = text;
}



-(void)upLoadImage:(UIImage*)image complete:(void(^)(NSString*imageUrl))complete
{
    
    [[NetworkTool shareManager] POST:[Interfacefile uploader] Param:@{} File:UIImageJPEGRepresentation(image, 0.8) fileKey:@"fileList" andFileName:@"fileName.jpg" andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            
            if([[responseObject objectForKey:@"data"] isKindOfClass:[NSArray class]]&&[[responseObject objectForKey:@"data"] count])
                complete([[responseObject objectForKey:@"data"] firstObject]);
        }else{
            [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
        
    }];
}



- (void)didSaveButton{
    if(self.workTypeField.text.length == 0)
    {
        [self showHint:@"请选择工作类型"];
        return;
    }
    if(self.workNameTextField.text.length == 0)
    {
        [self showHint:@"请输入单位名称"];
        return;
    }
    if(self.workLocalField.text.length == 0)
    {
        [self showHint:@"请选择工作地区"];
        return;
    }
    if(self.workLocalTextField.text.length == 0)
    {
        [self showHint:@"请输入工作地址"];
        return;
    }
    if(self.workTelTextField.text.length == 0)
    {
        [self showHint:@"请输入单位电话"];
        return;
    }
    if(self.workTimeTextField.text.length == 0)
    {
        [self showHint:@"请选择工作时长"];
        return;
    }
    if(self.getMoneyTextField.text.length == 0)
    {
        [self showHint:@"请选择发薪日期"];
        return;
    }
    self.para.companyName = self.workNameTextField.text;
    self.para.companyAddress = [NSString stringWithFormat:@"%@&%@",[self.workLocalField.text stringByReplacingOccurrencesOfString:@" " withString:@""],self.workLocalTextField.text];
    self.para.companyTel = self.workTelTextField.text;
    
    
    [[NetworkTool shareManager] POST:[Interfacefile updateWorkDetailInfo] Param:[self.para toDictionary] andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            [self showHint:@"保存成功"];
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
    
}


- (UILabel *)setupLabelWith:(NSString *)title{
    
    UILabel * label = [UILabel new];
    
    label.textColor = ColorWithRGB(0x303c41);
    label.font = [UIFont systemFontOfSize:13.5 * SCREENH6];
    label.text = title;
    
    return label;
}


- (UIButton *)setupTitleButtonWith:(NSString *)string{
    
    UIButton * button = [UIButton new];
    
    [button setTitleColor:ColorWithRGB(0xcecece) forState:UIControlStateNormal];
    [button addTarget:self action:@selector(didSelectedButton:) forControlEvents:UIControlEventTouchUpInside];
    button.titleLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    
    return button;
}


- (UITextField *)setupTextField:(NSString *)title{
    
    UITextField * textField = [[UITextField alloc] init];
    
    textField.borderStyle = UITextBorderStyleNone;
    textField.backgroundColor = [UIColor clearColor];
    textField.layer.borderColor = [[UIColor clearColor] CGColor];
    textField.textAlignment = NSTextAlignmentRight;
    //设置光标颜色
    textField.tintColor = ColorWithRGB(0xcecece);
    //修改占位符文字颜色
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = ColorWithRGB(0xcecece);
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:12 * SCREENH6];
    //修改占位符文字颜色
    textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:title attributes:attrs];
    textField.textColor = ColorWithRGB(0x303c41);
    textField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 22 * SCREENH6, 0)];
    //设置显示模式为永远显示(默认不显示)
    textField.leftViewMode = UITextFieldViewModeAlways;
    textField.font = [UIFont fontWithName:@"PingFangSC-Regular" size:13 * SCREENH6];
    
    return textField;
}


- (UIImageView *)setupRightImage{
    
    UIImageView * imageView = [UIImageView new];
    
    imageView.image = [UIImage imageNamed:@"返回-拷贝-6"];
    
    return imageView;
}



- (UIView *)setupLineView{
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xdbdbdb);
    
    return lineView;
}


- (void)backToLastView{
    
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)getPageModel
{
    ParaModel*para = [ParaModel new];
    
    
    [[NetworkTool shareManager] POST:[Interfacefile loadCurrentPersonalInfo] Param:[para toDictionary] andWaitStr:@"" waitView:self.view success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            self.pageModel = [[MemberInfoModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            self.para.workType = self.pageModel.workType;
            self.para.companyName = self.pageModel.workDetailInfoJson.companyName;
            self.para.companyAddress = self.pageModel.workDetailInfoJson.companyAddress;
            self.para.companyTel = self.pageModel.workDetailInfoJson.companyTel;
            self.para.workPhoto = self.pageModel.workDetailInfoJson.workPhoto;
            self.para.workDuration = self.pageModel.workDetailInfoJson.workDuration;
            self.para.workPayDate = self.pageModel.workDetailInfoJson.workPayDate;
            [self getTypeModel:nil];
            
        }else{
            
            [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        [self showHint:@"网络错误"];
    }];
    
}

-(void)getTypeModel:(void(^)())complete
{
    ParaModel*para = [ParaModel new];
    
    
    [[NetworkTool manager] POST:[Interfacefile loadUserRelatedEnums] Param:[para toDictionary] andWaitStr:@"" waitView:nil success:^(id  _Nullable responseObject) {
        if([[responseObject objectForKey:@"code"]intValue]==0)
        {
            self.typePageModel = [[MemberInfoTypePageModel alloc] initWithDictionary:[responseObject objectForKey:@"data"] error:nil];
            if(complete)
            {
                complete();
            }else
            {
                [self updateView];
            }
        }else{
            if(complete)
                [self showHint:[responseObject objectForKey:@"message"]];
            
            
        }
    } andFailure:^(NSError * _Nonnull error) {
        if(complete)
            [self showHint:@"网络错误"];
    }];
    
}
-(void)updateView
{
    
    
    [self.cameraButton sd_setImageWithURL:[NSURL URLWithString:self.pageModel.workDetailInfoJson.workPhoto] forState:UIControlStateNormal];
    self.workNameTextField.text = self.pageModel.workDetailInfoJson.companyName;
    self.workTelTextField.text = self.pageModel.workDetailInfoJson.companyTel;
    
    NSArray *array = [self.pageModel.workDetailInfoJson.companyAddress componentsSeparatedByString:@"&"];
    
    self.workLocalField.text = array.firstObject;
    self.workLocalTextField.text = array.lastObject;
    
    [self.typePageModel.workTypeEnum enumerateObjectsUsingBlock:^(MemberInfoTypeModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if(self.pageModel.workType&& ([obj.value integerValue]==[self.pageModel.workType intValue]))
        {
            self.workTypeField.text = obj.name;
        }
    }];
    [self.typePageModel.addressSpanEnum enumerateObjectsUsingBlock:^(MemberInfoTypeModel*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if(self.pageModel.workDetailInfoJson.workDuration&& ([obj.value integerValue]==[self.pageModel.workDetailInfoJson.workDuration intValue]))
        {
            self.workTimeTextField.text = obj.name;
        }
    }];

    if([self.pageModel.workDetailInfoJson.workPayDate intValue])
    self.getMoneyTextField.text = [NSString stringWithFormat:@"%d号",[self.pageModel.workDetailInfoJson.workPayDate intValue]];
    else
    {
        self.getMoneyTextField.text = nil;

    }
}

#pragma mark delegate
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.workNameTextField resignFirstResponder];
    [self.workLocalTextField resignFirstResponder];
    [self.workTelTextField resignFirstResponder];
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    [self.workNameTextField resignFirstResponder];
    [self.workLocalTextField resignFirstResponder];
    [self.workTelTextField resignFirstResponder];
    return YES;
}
-(ParaModel*)para
{
    if(!_para)
    {
        _para = [ParaModel new];
    }
    return _para;
}

@end
